<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-codeRecord-add">
			<div class="form-group" >	
				<label class="col-sm-3 control-label">代理商名称：</label>
				<div class="col-sm-8">
					<input id="name" name="name" class="form-control" type="text">
					<input  type="hidden" id="agentNameList" value=""/><br>
				</div>
			</div>
			<div class="form-group" style="display: none;">	
				<label class="col-sm-3 control-label">代理商id：</label>
				<div class="col-sm-8">
					<input id="agentId" name="agentId" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">交易数量：</label>
				<div class="col-sm-8">
					<input id="count" name="count" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">交易单价：</label>
				<div class="col-sm-8">
					<input id="price" name="price" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">是否扣公司码：</label>
				<div class="col-sm-8">
					<select id="isCompany" name="isCompany"  class="form-control m-b">
						<option value="0">是</option>
						<option value="1">否</option>
					</select>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "system/codeRecord";
	   	var prefix1 = ctx + "system/hatchetAgent";
        var agentNameList = [];
		$("#form-codeRecord-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});
		  $(function() {
	        	agents();
	         	//代理商名称自动补全
	         	$("#name").autocomplete({
	        		source: agentNameList
	        	});
		  })	
		function submitHandler() {
	        if ($.validate.form()) {
	        	 //做加码的业务
	            $.ajax({
	 		        url:prefix+"/add", //请求后台
	 		        dataType:"json",
	 		       type : "POST",
					data: {
						"name":$("#name").val().trim(),
						"count":$("#count").val().trim(),
						"price":$("#price").val().trim(),
						"isCompany":$("#isCompany").val().trim()
					},
	 		        success:function(re){
	 		        	$("#tixianMoney").val("");
	 		      		if(re.status=="SUCCESS"){
	 		      			$.modal.msgSuccess(re.msg);
	 		      			//重新显示剩下金额
	 		      			var nowmoney = re.nowmoney;
	 		      			$("#totalMoney").text(nowmoney);
	 		      			return;
	 		      		} else if(re.status=="FAIL"){
	 		      			$.modal.alertError(re.msg);
	 		      		}
	 		        }
	 		    });
	        }
	    }
		  
		//查找代理商
 		function agents(){
	    		var array=[];
				$.ajax({
					url: prefix1 + "/getAgentAll",
					async:false,
					type:"POST",
					data:{},
					success: function(result) {
						$.each(result, function(i,v) {
							if (v.agentName != null && v.agentName != undefined) {
								agentNameList.push(v.agentName);
								var arrays = {};
								arrays.value = v.agentName;
								arrays.id = v.id;
								array.push(arrays);
							}
						});
					}
				});
				return array;
	    	} 
	</script>
</body>
</html>
